package com.qf.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class RabbitMqConfig {

    @Bean
    public Queue queue(){
        return new Queue("qf-live-email-queue");
    }

    @Bean
    public FanoutExchange fanoutExchange(){
        return new FanoutExchange("qf-live-email");
    }

    @Bean
    Binding bindqueueToFanoutExchange(Queue  queue,FanoutExchange fanoutExchange){
        return BindingBuilder.bind(queue).to(fanoutExchange);
    }


    @Bean("payQueue")
    public Queue payQueue(){
        return new Queue("pay-queue");
    }


    @Bean("deadpayQueue")
    public Queue deadpayQueue(){

        Map map = new HashMap<>();
        map.put("x-dead-letter-exchange","pay-topic-exchange");
        map.put("x-dead-letter-routing-key","pay");
        return new Queue("dead-pay-queue",false,false,false,map);
    }

    @Bean("payTopicExchange")
    public TopicExchange topicExchange(){
        return new TopicExchange("pay-topic-exchange");
    }

    @Bean("deadpayTopicExchange")
    public TopicExchange deadTopicExchange(){
        return new TopicExchange("dead-pay-topic-exchange");
    }

    @Bean
    Binding bindpayQueueToPayTopic(@Qualifier("payQueue")Queue queue,@Qualifier("payTopicExchange")TopicExchange topicExchange){
        return BindingBuilder.bind(queue).to(topicExchange).with("pay.#");
    }

    @Bean
    Binding binddeadpayQueueTodeadPayTopic(@Qualifier("deadpayQueue")Queue queue,@Qualifier("deadpayTopicExchange")TopicExchange topicExchange){
        return BindingBuilder.bind(queue).to(topicExchange).with("pay.#");
    }
}

